package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ASUS
 */
@RestController
@RequestMapping("/iot")
@Api(tags = "设备管理")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @PostMapping("/syncProductList")
    @ApiOperation("拿物联网产品")
    public ResponseResult syncProductList(){
        deviceService.queryProductList();
        return ResponseResult.success();
    }
    @GetMapping("/allProduct")
    @ApiOperation("所有产品")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> productVoList = deviceService.allProductList();
        return ResponseResult.success(productVoList);
    }
    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }
    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询设备")
    public ResponseResult<PageResponse<DeviceVo>> queryPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                @RequestParam(value = "deviceName", required = false) String deviceName
                                                                , @RequestParam(value = "productKey", required = false) String productKey
                                                                , @RequestParam(value = "locationType", required = false) Integer locationType
    ){
        PageResponse<DeviceVo> pageResponse = deviceService.queryPage(pageNum,pageSize,deviceName,productKey,locationType);
        return ResponseResult.success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("查询设备详情")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备物模型运行状态")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.queryDevicePropertyStatus(request);
    }
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查询指定产品的物模型中的功能定义")
    public ResponseResult QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request){
        return deviceService.queryThingModelPublished(request);
    }
    @PostMapping("/UpdateDevice")
    @ApiOperation("修改设备名称")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult DeleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }
    @PostMapping("/deviceOpenDoor/{iotId}")
    @ApiOperation("设备开门")
    public ResponseResult deviceOpenDoor(@PathVariable("iotId") String iotId){
         deviceService.deviceOpenDoor(iotId);
        return ResponseResult.success();
    }
}
